/**
 * Created by chenyong on 2015/7/16.
 */

var express = require('express');
var passport = require('passport');
var auth = require('../auth.service');
var crypto = require('crypto')

var router = express.Router();

router.get('/',function(req,res,next){
    req.session = req.session || {};
    req.session.authState = crypto.createHash('sha1').update(-(new Date()) + '').digest('hex');
    passport.authenticate('wechat', {
        state: req.session.authState
    })(req, res, next);
});



router.get('/callback', passport.authenticate('wechat', {
    //successRedirect:'/auth/success',
    failureRedirect: '/auth/failure',
    session:false
}), auth.setTokenCookie);




module.exports = router;